Imports System.Data.SqlClient

Friend Class DBVField
    Inherits DBBase

    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub Load(ByRef oObject As SQLAutoDocLib.VField)
        Dim sSQL As String = "select"
        sSQL = sSQL & "     [ViewID],"
        sSQL = sSQL & "     [ViewRevID],"
        sSQL = sSQL & "     [Name],"
        sSQL = sSQL & "     [Desc],"
        sSQL = sSQL & "     [Type],"
        sSQL = sSQL & "     [Size],"
        sSQL = sSQL & "     [Scale],"
        sSQL = sSQL & "     [Precision],"
        sSQL = sSQL & "     [Order],"

        sSQL = sSQL & "     [IsDeleted],"
        sSQL = sSQL & "     [CreateName],"
        sSQL = sSQL & "     [CreateDate],"
        sSQL = sSQL & "     [ChangeName],"
        sSQL = sSQL & "     [ChangeDate]"
        sSQL = sSQL & " from"
        sSQL = sSQL & "     tDDVFields"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        Dim oData As DataTable = MyBase.ExecuteReadToDataTable(sSQL)

        With oObject
            .ViewID = oData.Rows(0).Item("ViewID")
            .ViewRevID = oData.Rows(0).Item("ViewRevID")
            .Name = oData.Rows(0).Item("Name")
            .Desc = NullToString(oData.Rows(0).Item("Desc"))
            .Type = oData.Rows(0).Item("Type")
            .Size = oData.Rows(0).Item("Size")
            .Scale = NullToNumber(oData.Rows(0).Item("Scale"))
            .Precision = oData.Rows(0).Item("Precision")
            .Order = oData.Rows(0).Item("Order")

            .CreateName = oData.Rows(0).Item("CreateName")
            .CreateDate = oData.Rows(0).Item("CreateDate")
            .ChangeName = NullToString(oData.Rows(0).Item("ChangeName"))
            .ChangeDate = NullToString(oData.Rows(0).Item("ChangeDate"))
        End With

        oData.Dispose()
    End Sub

    Public Sub Update(ByRef oObject As SQLAutoDocLib.VField)
        Dim sSQL As String = "update tDDVFields set"
        sSQL = sSQL & "     [ViewID]=" & ValueToDBValue(oObject.ViewID) & ","
        sSQL = sSQL & "     [ViewRevID]=" & ValueToDBValue(oObject.ViewRevID) & ","
        sSQL = sSQL & "     [Name]=" & ValueToDBValue(oObject.Name) & ","
        sSQL = sSQL & "     [Desc]=" & ValueToDBValue(oObject.Desc) & ","
        sSQL = sSQL & "     [Type]=" & ValueToDBValue(oObject.Type) & ","
        sSQL = sSQL & "     [Size]=" & ValueToDBValue(oObject.Size) & ","
        sSQL = sSQL & "     [Scale]=" & ValueToDBValue(oObject.Scale) & ","
        sSQL = sSQL & "     [Precision]=" & ValueToDBValue(oObject.Precision) & ","
        sSQL = sSQL & "     [Order]=" & ValueToDBValue(oObject.Order) & ","

        sSQL = sSQL & "     [CreateName]=" & ValueToDBValue(oObject.CreateName) & ","
        sSQL = sSQL & "     [CreateDate]=" & ValueToDBValue(oObject.CreateDate) & ","
        sSQL = sSQL & "     [ChangeName]=" & ValueToDBValue(oObject.ChangeName) & ","
        sSQL = sSQL & "     [ChangeDate]=" & ValueToDBValue(oObject.ChangeDate)
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        MyBase.ExecuteNonQuery(sSQL)
    End Sub

    Public Sub Add(ByRef oObject As SQLAutoDocLib.VField)
        Dim oNextID As New DBNextIDValue("VField")
        Dim lNextID As Long = oNextID.NextValue
        oObject.ID = lNextID

        Dim sSQL As String = "insert into tDDVFields ("
        sSQL = sSQL & "     [ID],"
        sSQL = sSQL & "     [ViewID],"
        sSQL = sSQL & "     [ViewRevID],"
        sSQL = sSQL & "     [Name],"
        sSQL = sSQL & "     [Desc],"
        sSQL = sSQL & "     [Type],"
        sSQL = sSQL & "     [Size],"
        sSQL = sSQL & "     [Scale],"
        sSQL = sSQL & "     [Precision],"
        sSQL = sSQL & "     [Order],"

        sSQL = sSQL & "     [CreateName],"
        sSQL = sSQL & "     [CreateDate],"
        sSQL = sSQL & "     [ChangeName],"
        sSQL = sSQL & "     [ChangeDate]) values ("

        sSQL = sSQL & ValueToDBValue(oObject.ID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.ViewID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.ViewRevID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Name) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Desc, 2500) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Type) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Size) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Scale) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Precision) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Order) & ","

        sSQL = sSQL & ValueToDBValue(oObject.CreateName) & ","
        sSQL = sSQL & ValueToDBValue(oObject.CreateDate) & ","
        sSQL = sSQL & ValueToDBValue(oObject.ChangeName) & ","
        sSQL = sSQL & ValueToDBValue(oObject.ChangeDate) & ")"

        MyBase.ExecuteNonQuery(sSQL)
    End Sub

    Public Sub Delete(ByRef oObject As SQLAutoDocLib.VField)
        Dim sSQL As String = "delete from tDDVFields"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        MyBase.ExecuteNonQuery(sSQL)
    End Sub
End Class
